package com.distortiongames.level27.generation.random
{
	import com.distortiongames.level27.generation.Element;
	import com.distortiongames.level27.generation.Generator;
	
	/**
	 * ...
	 * @author Jefferson Wagner
	 */
	public class ElementalChance
	{
		private var chanceForNeutral:Number, chanceForWater:Number, chanceForFire:Number, chanceForWind:Number, chanceForEarth:Number;
		private var element:int;
		
		public function ElementalChance(element:int)
		{
			this.element = element;
			switch (element)
			{
				case Element.WATER: 
					chanceForWind = 0;
					chanceForWater = 40;
					chanceForNeutral = 40;
					chanceForFire = 10;
					chanceForEarth = 10;
					break;
				case Element.FIRE: 
					chanceForWind = 10;
					chanceForWater = 10;
					chanceForNeutral = 40;
					chanceForFire = 40;
					chanceForEarth = 0;
					break;
				case Element.WIND: 
					chanceForWind = 40;
					chanceForWater = 0;
					chanceForNeutral = 40;
					chanceForFire = 10;
					chanceForEarth = 10;
					break;
				case Element.EARTH: 
					chanceForWind = 10;
					chanceForWater = 10;
					chanceForNeutral = 40;
					chanceForFire = 0;
					chanceForEarth = 40;
					break;
			}
		}
		
		public function roll():int
		{
			var result:int = -1;
			var chance:int = Generator.random.nextInt(100, 1);
			if (chance <= chanceForWater)
				result = Element.WATER;
			else if (chance <= chanceForWater + chanceForFire)
				result = Element.FIRE;
			else if (chance <= chanceForWater + chanceForFire + chanceForWind)
				result = Element.WIND;
			else if (chance <= chanceForWater + chanceForFire + chanceForWind + chanceForEarth)
				result = Element.EARTH;
			else if (chance <= chanceForWater + chanceForFire + chanceForWind + chanceForEarth + chanceForNeutral)
				result = Element.NEUTRAL;
				return result;
		}
	}
}